local skel = fk.CreateSkill {
  name = "lb__yingze",
}

Fk:loadTranslationTable {
  ["lb__yingze"] = "盈泽",
  [":lb__yingze"] = "准备阶段，你可以视为使用一张【推心置腹】，你因此获得牌后，若花色相同，则你可以将其中一张牌当【无中生有】使用。",

  ["#lb__yingze"] = "盈泽：你可以视为使用一张【推心置腹】",
  ["#lb__yingze_use"] = "盈泽：你可以将其中一张牌当【无中生有】使用",

  ["$lb__yingze1"] = "哎呀~ 不太好办啊~",
  ["$lb__yingze2"] = "机会稍纵即逝，等不得呀~",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "sincere_treat",
      skill_name = skel.name,
      prompt = "#lb__yingze",
      cancelable = true,
      skip = true,
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use ---@type UseCardDataSpec
    use.extra_data = use.extra_data or {}
    use.extra_data.lb__yingze = player.id
    room:useCard(use)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local parent = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect, true) --父事件
    if not (parent and parent.data.use and parent.data.use.extra_data and parent.data.use.extra_data.lb__yingze == player.id) then
      return
    end
    for _, move in ipairs(data) do
      if move.proposer and move.proposer == player and move.moveReason == fk.ReasonPrey then
        if #move.moveInfo > 1 and table.every(move.moveInfo, function(info)
              return Fk:getCardById(info.cardId).suit == Fk:getCardById(move.moveInfo[1].cardId).suit
            end) then
          local ids = table.map(table.filter(move.moveInfo, function(info)
            return table.contains(player:getCardIds("h"), info.cardId)
          end), function(info)
            return info.cardId
          end)
          if #ids > 0 then
            event:setCostData(self, { cards = ids })
            return true
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "ex_nihilo",
      skill_name = skel.name,
      prompt = "#lb__yingze_use",
      cancelable = true,
      skip = true,
      card_filter = {
        cards = event:getCostData(self).cards,
        n = 1,
      }
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use ---@type UseCardDataSpec
    room:useCard(use)
  end,
})

return skel